<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="案件编号">
              <el-input
                v-model="query.caseCode"
                class="search-ipt"
                placeholder="请输入案件编号"
                maxlength="255"
              />
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="所属区域">
              <el-select
                class="w-100"
                v-model="query.levelArea1"
                placeholder="请选择所属区域"
                @change="levelArea1Change"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in regionNewArr"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="所属街道">
              <el-select
                class="w-100"
                v-model="query.levelArea2"
                placeholder="请选择所属街道"
                @change="levelArea2Change"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in StreetArr1"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="所属社区">
              <el-select
                class="w-100"
                v-model="query.levelArea3"
                placeholder="请选择所属社区"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in CommunityArr"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="案件来源">
              <el-select
                class="w-100"
                v-model="query.caseSource"
                placeholder="请选择案件来源"
              >
                <el-option
                  :label="item.name"
                  :value="item.value"
                  v-for="item in SourceTypeArr"
                  :key="item.id"
                ></el-option
              ></el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="行业领域">
              <el-select
                class="w-100"
                v-model="query.industry"
                placeholder="请选择行业领域"
                @change="industryChange"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in IndustryAreaArr"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="权利名称">
              <el-select
                class="w-100"
                v-model="query.bigClass"
                placeholder="请选择权利名称"
                @change="powerChange"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in TitleOfPowerArr"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="事项清单">
              <el-select
                class="w-100"
                v-model="query.smallClass"
                placeholder="请选择事项清单"
              >
                <el-option
                  :label="item.name"
                  :value="item.id"
                  v-for="item in ChecklistArr"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" class="btn-col">
            <el-button size="mini" class="search-btn" @click="queryData"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
          >刷新</el-button
        >
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 465px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="nodeName"
            label="办理环节"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span class="rect" :class="'rect-color-' + scope.row.nodeCode">{{
                scope.row.nodeName
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nodeParentName"
            label="前办理环节"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <span
                class="rect"
                :class="'rect-color-' + scope.row.nodeParentCode"
                >{{ scope.row.nodeParentName }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="nodeParentUserName"
            label="前环节处理人"
            show-overflow-tooltip
          />
          <el-table-column
            prop="creatDeptName"
            label="办理部门"
            show-overflow-tooltip
          />
          <el-table-column
            prop="caseCode"
            label="案件编号"
            show-overflow-tooltip
          />
          <el-table-column
            prop="caseTitle"
            label="案件标题"
            show-overflow-tooltip
          />
          <el-table-column
            prop="planCompleteTime"
            label="预计完成时间"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>
                {{ parseTime(scope.row.planCompleteTime) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120" fixed="right">
            <template slot-scope="scope">
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click="gotoCaseDetail(scope.row.caseCode)"
                >详情</el-button
              >
              <el-button
                class="table-inner-btn"
                type="text"
                size="mini"
                @click="handleShowTaskHistory(scope.row.caseCode)"
                >流程</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.page"
          :limit.sync="query.size"
          @pagination="initData"
        />
      </div>
    </div>
    <!-- 弹窗框 -->
    <TaskHistoryDialog
      custom-class="custom-dialog"
      @closeDialog="taskHistoryDialogVisible = false"
      :dialogVisible="taskHistoryDialogVisible"
      :caseCode="caseCode"
    ></TaskHistoryDialog>
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { parseTime } from "@/utils/index";
import {
  caseTypeList,
  region,
  industryArea,
  categoryType,
  caseAllData,
} from "@/api/case.js";
import TaskHistoryDialog from "./../casedeal/components/taskHistoryDialog";
export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
    TaskHistoryDialog,
  },
  data() {
    return {
      query: {
        total: 100,
        page: 1,
        size: 10,
        levelArea1: "", // 所属区域
        levelArea2: "", // 所属区域
        levelArea3: "", // 所属街道
        industry: "", //行业领域
        bigClass: "", // 权利名称
        smallClass: "", // 事项清单
        caseCode: "", //案件编号
        caseSource: "", //案件来源
        nodeCode: "105", //关联的节点编码
      },
      regionNewArr: [], //所属区域下拉框
      SourceTypeArr: [], //来源类型得下拉框
      StreetArr1: [], //所属街道的下拉框
      CommunityArr: [], //所属社区的下拉框
      IndustryAreaArr: [], //行业领域下拉框
      IndustryAreaAllArr: [], //行业领域所有
      TitleOfPowerArr: [], //权力名称下拉框
      ChecklistArr: [], //事项清单下拉框
      caseTypeArr: [], //案件分类
      tableLoading: false,
      tableData: [],
      isShow: true,
      taskHistoryDialogVisible: false,
      caseCode: "",
    };
  },
  created() {
    this.initData();
    // 调用获取案件列表的接口
    // this.getCaseList();

    // 调用获取所属区域的接口
    this.getRegion(1);

    // 调用获取来源信息的接口
    this.getSourceMessage();

    //
    this.getIndustryArea();
  },
  methods: {
    parseTime,
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      caseAllData(this.query)
        .then((result) => {
          let { rows, code, total } = result;
          if (code == 200) {
            this.tableData = rows;
            this.query.total = total;
          }
        })
        .catch({});
    },

    // 查询数据
    queryData() {
      this.initData();
    },
    gotoCaseDetail(data) {
      this.$router.push({
        name: "CaseDetail",
        params: { caseCode: data },
        dialogType: "distribute",
      });
    },
    // 获取案件分类的列表信息
    getCaseList() {
      caseTypeList({ pageNum: 1 })
        .then((result) => {
          let { rows, code } = result;
          if (code == 200) this.caseTypeArr = rows;
        })
        .catch({});
    },

    // 获取所属区域
    getRegion(levelId) {
      region({
        level: levelId,
      })
        .then((result) => {
          let { rows, code } = result;
          if (code == 200) this.regionNewArr = rows;
        })
        .catch({});
    },

    // 所属区域的change事件
    levelArea1Change() {
      region({
        parentCode: this.query.levelArea1,
      })
        .then((result) => {
          let { rows, code } = result;
          if (code == 200) this.StreetArr1 = rows;
        })
        .catch({});
    },

    // 所属街道的change事件
    levelArea2Change() {
      region({
        parentCode: this.query.levelArea2,
      })
        .then((result) => {
          let { rows, code } = result;
          if (code == 200) this.CommunityArr = rows;
        })
        .catch({});
    },

    // 获取行业领域
    getIndustryArea() {
      industryArea({
        // parentId: 0,
      })
        .then((result) => {
          let { rows } = result;
          this.IndustryAreaAllArr = rows;
          rows.forEach((item) => {
            if (item.parentId == 0) {
              this.IndustryAreaArr.push(item);
            }
          });
        })
        .catch({});
    },

    // 行业领域的change事件
    industryChange() {
      this.IndustryAreaAllArr.forEach((item) => {
        if (item.parentId == this.query.industry) {
          this.TitleOfPowerArr.push(item);
        }
      });
    },

    // 权力名称的change事件
    powerChange() {
      this.IndustryAreaAllArr.forEach((item) => {
        if (item.parentId == this.query.bigClass) {
          this.ChecklistArr.push(item);
        }
      });
    },

    // 获取来源信息
    getSourceMessage() {
      categoryType({
        sysGroup: "caseSource",
      })
        .then((result) => {
          let { rows } = result;
          this.SourceTypeArr = rows;
        })
        .catch({});
    },
    handleShowTaskHistory(data) {
      this.caseCode = data;
      this.taskHistoryDialogVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
